<?php
class Admin_Model_Catalog extends Zend_Db_Table_Abstract
{
    protected $_table = 'cmdcatalogue';
    
	public function getListCatalog() 
	{
		$sql = $this->getAdapter()->select()
		->from($this->_table)
		->where('dtdeleted is null')
		->order('p_cmdcatalogue desc');
		
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function getCatalog($id)
	{
		$sql = $this->getAdapter()->select('c.*')
		->from($this->_table . ' as c')
		->joinInner('pays as p', 'p.p_pays = c.f_pays', array('nom as pays_nom'))
		->where('p_cmdcatalogue = ?', $id);
	
		return $this->getAdapter()->fetchRow($sql);
	}
	
	public function removeCatalog($id)
	{
		$this->getAdapter()->delete($this->_table, "p_cmdcatalogue =" . $id);
		return true;
	}
	
	public function getDateVentes($strid)
	{
	    $sql = 'SELECT dtvente FROM ventes WHERE p_ventes = ' . str_replace("cat","", $strid);
	    return $this->getAdapter()->fetchRow($sql);
	}
	
	public function updateCatalog($id, $paye, $catOk, $traitee=0)
	{
	    $sql = "UPDATE cmdcatalogue SET ";
	    $sql .= "paye = $paye, ";
	    $sql .= "envoye='$catOk' ";
	    if($traitee) {
	        $sql .= ",traitee = 1, ";
	        $sql .= "dttraitee = '". date('Y-m-d') ."', ";
	        $sql .= "hrtraitee = '". date('H:i:s') ."' ";
        }
	    
	    $sql .= " WHERE p_cmdcatalogue = $id";
    //echo $sql;exit;
	    return $this->getAdapter()->query($sql);
	}
}